<template>
  <div class="age">
    <div class="title">
      <p>年龄比例</p>
      <img src="../../images/dataScreen-title.png" alt="">
    </div>
    <!-- 图形图标容器 -->
    <div class="charts" ref="charts">

    </div>
  </div>
</template>
<script setup lang='ts'>
import { ref, onMounted } from 'vue'
import * as echarts from 'echarts'
// 获取图形图表节点
let charts = ref()

// 组件挂载完毕，初始化echarts实例
onMounted(() => {
  // 获取echarts类的实例
  let mychart = echarts.init(charts.value)
  // 设置实例的配置项
  let options = {
    tooltip: {
      trigger: 'item'
    },
    // 右侧图例样式配置
    legend: {
      right: 20, // 距离右侧位置
      top: 'center',
      orient: 'vertical', // 图例组件方向设置
      textStyle: {
        color: "white",
        fontSize: 14
      }

    },
    series: [
      {
        name: '类目',
        type: 'pie',
        radius: ['40%', '70%'], // 如果之为数据，数组的第一项是内半径，第二项是外半径
        avoidLabelOverlap: false,
        // 图表的样式
        itemStyle: {
          borderRadius: 10,
          borderColor: '#fff',
          borderWidth: 2
        },
        label: {
          show: true,
          position: 'inside',
          color: 'white'
        },
        labelLine: {
          show: false
        },
        data: [
          { value: 1048, name: '新闻' },
          { value: 735, name: '娱乐' },
          { value: 580, name: '直播' },
          { value: 484, name: '娱乐' },
          { value: 300, name: '财经' }
        ]
      }
    ],
    // 图表布局
    grid: {
      top: 0,
      bottom: 0,
      left: 0,
      right: 0
    }
  }
  mychart.setOption(options)
})
</script>
<style scoped lang="scss">
.age {
  width: 100%;
  height: 100%;
  background: url(../../images/dataScreen-main-cb.png) no-repeat;
  background-size: 100% 100%;

  .title {
    color: white;
    font-size: 20px;
    margin-left: 20px;
  }

  .charts {
    height: 260px;
    left: -50px;
  }
}
</style>